<template>
  <div id="order">
    <el-tabs type="border-card">
      <el-tab-pane>
        <span slot="label"> 新订单<el-badge :value="order.newOrderNum" class="item"> </el-badge></span>
        <div v-if="order.newOrderNum==0">
          <el-empty description="暂无新订单">
            <el-button type="primary" @click="showUserOrder">刷新看看</el-button>
          </el-empty>
        </div>
        <div class="neworder" v-if="order.newOrderNum!=0">
          <el-row>
            <el-col :span="24">
              <el-row>
                <el-col :span="14" style="margin-left: 20px; margin-top: 10px;">
                  <el-row>
                    <el-col :span="24">
                      <el-card class="box-card">
                        <el-row>
                          <el-col :span="20">
                            <span style="font-size: 15px;">买家饿极了，建议尽快出餐</span>
                          </el-col>
                          <el-col :span="3">
                            <el-button type="primary" plain @click="orderOut">立即出餐</el-button>
                          </el-col>
                        </el-row>
                        <el-row>
                          <el-col :span="10">
                            <el-row>
                              <el-col :span="24">
                                <span style="font-size: 20px;">订餐人：{{order.receiveName}}</span>
                              </el-col>
                            </el-row>
                            <el-row>
                              <el-col :span="24">
                                <span style="font-size: 15px; color: gray;">地址：{{order.address}}</span>
                              </el-col>
                            </el-row>
                          </el-col>
                          <el-col :span="6" :offset="8">
                            <i class="el-icon-phone"
                              style="color: black; font-size: 15px;line-height: 50px; margin-left: 20px;"></i>
                            <span style="font-size: 15px; ">{{order.orderPhone}}</span>
                          </el-col>
                        </el-row>
                        <el-row>
                          <el-col :span="8">
                            <span style="font-size: 15px; color: #ffaa00; ;">备注:</span>
                            <span style="font-size: 15px; ">{{order.remarks}}</span>
                          </el-col>
                        </el-row>
                        <el-row>
                          <el-col :span="10">
                            <span style="font-size: 15px; color: #ffaa00; ;">配送方式:</span>
                            <span style="font-size: 15px; ">{{order.dispatching}}</span>
                          </el-col>
                        </el-row>
                        <el-row>
                          <el-col :span="24">
                            <el-collapse @change="handleChange">
                              <el-collapse-item title="订单详情">
                                <div v-for="food in order.items" style="margin-top:15px ;">
                                  <el-row>
                                    <el-col :span="4">
                                      <span style="font-size: 15px; ">{{food.foodName}}</span>
                                    </el-col>
                                    <el-col :span="3" :offset="10" style="font-weight: bold;">

                                      X<span style="margin-left: 5px; font-size: 17px; ">{{food.count}}</span>
                                    </el-col>
                                    <el-col :span="4" :offset="3">
                                      <span style="font-size: 16px;">{{food.price}}</span>
                                    </el-col>
                                  </el-row>

                                </div>
                                <el-row>
                                  <el-col :span="4"><span style="font-size: 14px; color:dimgrey">包装费:
                                      {{order.packPrice}}</span></el-col>
                                </el-row>
                                <el-row>
                                  <el-col :span="4"><span style="font-size: 14px; color:dimgrey">配送费:
                                      {{order.packPrice}}</span></el-col>
                                </el-row>
                                <el-row>
                                  <el-col :span="4" :offset="19"><span style="font-size: 16px; font-weight: bold;">总价:
                                      {{order.price}}</span></el-col>
                                </el-row>
                              </el-collapse-item>
                            </el-collapse>
                          </el-col>
                        </el-row>
                      </el-card>
                    </el-col>
                  </el-row>

                </el-col>

                <el-col :span="9" style="margin-left: 10px; margin-top: 10px;">
                  <el-row>
                    <el-col>
                      <el-card class="box-card data-card">
                        <div slot="header" class="clearfix">
                          <span>今日总览</span>
                        </div>
                        <el-row>
                          <el-col :span="12">
                            <el-row>
                              <el-col :span="14" :offset="7">
                                <span
                                  style="color: gray; font-size: 50px;font-family: Arial, Helvetica, sans-serif;text-align: center;">{{order.allOrderCount}}</span>
                              </el-col>
                            </el-row>
                            <el-row>
                              <el-col :span="14" :offset="6">
                                <span>今日订单</span>
                              </el-col>
                            </el-row>
                          </el-col>
                          <el-col :span="12">
                            <el-row>
                              <el-col :span="14">
                                <span
                                  style="color:rgb(48, 148, 250); font-size: 50px; font-family: Arial, Helvetica, sans-serif; text-align: center;">￥{{order.turnover}}</span>
                              </el-col>
                            </el-row>
                            <el-row>
                              <el-col :span="14" :offset="5">
                                <span>今日营业额</span>
                              </el-col>
                            </el-row>
                          </el-col>
                        </el-row>
                      </el-card>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col>
                      <el-card class="box-card data-card">
                        <div slot="header" class="clearfix">
                          <span>待处理反馈</span>
                        </div>
                        <el-row>
                          <el-col :span="12">
                            <el-row>
                              <el-col :span="14" :offset="7">
                                <span
                                  style="color: gray; font-size: 50px;font-family: Arial, Helvetica, sans-serif;text-align: center;">
                                   {{ commentCount.lowScore }}
                                </span>
                              </el-col>
                            </el-row>
                            <el-row>
                              <el-col :span="14" :offset="6">
                                <span>未回复差评</span>
                              </el-col>
                            </el-row>
                          </el-col>
                          <el-col :span="12" style="text-align: center;">
                            <el-row>
                              <el-col :span="12" :offset="5">
                                <div style=" color: #ffaa00; font-size: 50px; font-family: Arial, Helvetica, sans-serif; ">
                                  {{ commentCount.notReplied }}
                                </div>
                              </el-col>
                            </el-row>
                            <el-row>
                              <el-col :span="14" :offset="5">
                                <span>未回复评价</span>
                              </el-col>
                            </el-row>
                          </el-col>
                        </el-row>




                      </el-card>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
        </div>
      </el-tab-pane>
      <el-tab-pane label="待接订单">
        <div v-show="waitOrders==null">
          <el-empty description="暂无待接订单">
            <el-button type="primary" @click="waitOrder">刷新看看</el-button>
          </el-empty>
        </div>
        <div v-show="waitOrders!=null" class="wait_table" style="margin: 10px 10px;">
          <el-table :data="waitOrders" style="width: 100%;">
            <el-table-column prop="orderNum" label="订单编号" width="200" align="center"> </el-table-column>
            <el-table-column prop="receiveName" label="订餐人" width="100" align="center"> </el-table-column>
            <el-table-column prop="orderPhone" label="电话" width="130" align="center"> </el-table-column>
            <el-table-column label="下单时间" width="230" align="center">
              <template slot-scope="scope">
                <i class="el-icon-time"></i>
                <span style="margin-left: 10px">{{ scope.row.orderDate }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="dispatching" label="配送方式" width="140" align="center"> </el-table-column>

            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button size="mini" @click="handleAccept(scope.row.orderNum)">接单</el-button>
                <el-button size="mini" type="danger" @click="showRefuse(scope.row.orderNum)">拒单</el-button>
              </template>
            </el-table-column>

            <el-table-column type="expand">
              <template slot-scope="props">
                <div v-for="food in props.row.items" style="margin-top:15px ;">
                  <el-row>
                    <el-col :span="4">
                      <span style="font-size: 15px; ">{{food.foodName}}</span>
                    </el-col>
                    <el-col :span="3" :offset="10" style="font-weight: bold;">

                      X<span style="margin-left: 5px; font-size: 17px; ">{{food.count}}</span>
                    </el-col>
                    <el-col :span="4" :offset="3">
                      <span style="font-size: 16px;">{{food.price}}</span>
                    </el-col>
                  </el-row>

                </div>
                <el-row>
                  <el-col :span="4"><span style="font-size: 14px; color:dimgrey">包装费:
                      {{props.row.packPrice}}</span></el-col>
                </el-row>
                <el-row>
                  <el-col :span="4"><span style="font-size: 14px; color:dimgrey">配送费:
                      {{props.row.packPrice}}</span></el-col>
                </el-row>
                <el-row>
                  <el-col :span="4" :offset="19"><span style="font-size: 16px; font-weight: bold;">总价:
                      {{props.row.price}}</span></el-col>
                </el-row>

              </template>
            </el-table-column>
          </el-table>
        </div>

        <!--   拒接订单弹窗 -->
        <el-dialog title="拒接订单窗口" :visible.sync="auditing_dialog">
          <el-form>
            <el-form-item label="拒接原因" label-width="120px">
              <el-input type="textarea" :rows="4" v-model="reason" autocomplete="off" placeholder="请填写拒单原因"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="auditing_dialog = false">取 消</el-button>
            <el-button type="primary" @click="handleRefuse">确 定</el-button>
          </div>
        </el-dialog>
      </el-tab-pane>
      <el-tab-pane label="全部订单">
       <div v-show="allDatas==null">
          <el-empty description="暂无订单记录">
            <el-button type="primary" @click="showAllOrders">刷新看看</el-button>
          </el-empty>
        </div>
        <div v-show="allDatas!=null">
         <el-table :data="allDatas" style="width: 100%;" >
            <el-table-column prop="orderNum" label="订单编号" width="200" align="center"> </el-table-column>
            <el-table-column prop="receiveName" label="订餐人" width="100" align="center"> </el-table-column>
            <el-table-column prop="orderPhone" label="电话" width="130" align="center"> </el-table-column>
            <el-table-column label="下单时间" width="230" align="center">
              <template slot-scope="scope">
                <i class="el-icon-time"></i>
                <span style="margin-left: 10px">{{ scope.row.orderDate }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="dispatching" label="配送方式" width="140" align="center"> </el-table-column>
            <el-table-column prop="price" label="订单总价" width="140" align="center"> </el-table-column>
            <el-table-column prop="state" label="订单状态" width="140" align="center"> </el-table-column>
          </el-table>

        </div>
      </el-tab-pane>



    </el-tabs>


  </div>
</template>


<script>
  export default {
    name: 'Order',
    data() {
      return {
        order: null,
        auditing_dialog: false,
        waitOrders: null,
        reason: "",
        refuseNum: "",
        allDatas: null,
        commentCount: {},
      }


    },
    methods: {
      getCommentCount() {
        this.$http.get("/commentInfo/count")
        .then(resp => {
          if (resp.data.code == 200) {
            this.commentCount = resp.data.data;
          }
        })
      },
      handleChange(val) {
        // console.log(val);
      },
      showRefuse(orderNum) {
        this.auditing_dialog = true;
        this.refuseNum = orderNum;
      },
      showUserOrder() {
        this.$http.get("/dietOrder/showStoreOrder").then(resp => {
          if (resp.data.code == 200) {
            this.order = resp.data.data
            console.log(this.order)
          }
        })
      },
      handleRefuse() {
        this.auditing_dialog = false;
        this.orderReview(this.refuseNum, 7, this.reason);
      },
      orderOut() {
        this.$http.post("/dietOrder/orderOut", {
          orderNum: this.order.orderNum
        }).then(resp => {
          if (resp.data.code == 200) {
            this.$message({
              message: '出餐成功',
              type: 'success'
            });
            this.order = resp.data.data;
            console.log(this.order);
          }else{
            this.$message.error(resp.data.message)
          }
        })
      },
      waitOrder() {
        this.$http.get("/dietOrder/showWaiteOrder").then(resp => {
          console.log(resp);
          if (resp.data.code == 200) {
            this.waitOrders = resp.data.data;
          }
        })
      },
      handleAccept(orderNum) {
        this.orderReview(orderNum, 2);
      },
      orderReview(orderNum, state, refuseReason) {
        this.$http.post("/dietOrder/orderReview", {
          orderNum: orderNum,
          state: state,
          refuseReason: refuseReason
        }).then(resp => {
          if (resp.data.code == 200) {
            this.showUserOrder();
            this.waitOrder();
            this.$message({
              message: '操作成功',
              type: 'success'
            });
            this.reason = "";
            this.refuseNum = "";
          }else{
            this.$message.error(resp.data.message)
          }
        })
      },

      showAllOrders() {
        this.$http.get("/dietOrder/showAllOrder").then(resp=>{
          if(resp.data.code==200){
            console.log(resp);
            this.allDatas = resp.data.data;
            console.log(this.allDatas);
          }
        })
      },

    },
    created() {
      this.showUserOrder();
      this.waitOrder();
      this.showAllOrders();
      this.getCommentCount();
    }
  }
</script>

<style scoped>

  .item {
    margin-left: 8px;
  }

  .neworder {
    background-color: #F5F5F5;
    width: 100%;
    bottom: 0;
  }

  .bg-left {
    position: absolute;
  }

  .bg-right {
    margin-left: 670px;
    margin-right: 20px;

  }

  .el-row {
    margin-bottom: 20px;

    &:last-child {
      /* margin-bottom: 10px; */
    }
  }


  .data-card {
    height: 210px;
  }

  .bg-purple {
    border-radius: 3px;
    min-height: 220 px;
  }

  #order {
    width: 100%;
    bottom: 0;

  }

  .order_item {
    font-size: 20px;
  }
</style>
